﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ninject.Core;
using Hotnet.Entity;
using Hotnet.Dal.NSDalMusic;
using Hotnet.Entity.Search;

namespace Hotnet.Biz.NSBizMusic
{
	public class BizMusicGroup : BaseBiz<MusicGroup>
	{
		private static DalMusicGroup db = new DalMusicGroup();

		private BizMusic _BizMusic;
		private BizMusic BizMusic
		{
			get
			{
				if (_BizMusic == null)
					_BizMusic = new BizMusic();
				return _BizMusic;
			}
		}


		private BizMusicGroupXTag _BizMusicGroupXTag;
		private BizMusicGroupXTag BizMusicGroupXTag
		{
			get
			{
				if (_BizMusicGroupXTag == null)
					_BizMusicGroupXTag = new BizMusicGroupXTag();
				return _BizMusicGroupXTag;
			}
		}


		private BizMusicGroupXMusic _BizMusicGroupXMusic;
		private BizMusicGroupXMusic BizMusicGroupXMusic
		{
			get
			{
				if (_BizMusicGroupXMusic == null)
					_BizMusicGroupXMusic = new BizMusicGroupXMusic();
				return _BizMusicGroupXMusic;
			}
		}


		public BizMusicGroup() : base(db) { }

		public MusicGroup[] List(int groupId, int pageNo, int pageSize, out int totalSize, SearchMusicCondition smc)
		{
			return db.List(groupId, pageNo, pageSize, out totalSize, smc);
		}

		public override void Insert(MusicGroup model)
		{
			model.AddTime = DateTime.Now;
			db.Insert(model);
			BizMusicGroupXTag.SaveTags(model.Tags, model.GroupID);
		}

		public override void Delete(int groupId)
		{
			BizMusicGroupXMusic.DeleteAllByGroupID(groupId);
			BizMusicGroupXTag.DeleteAllByGroupID(groupId);
			db.Delete(groupId);
		}

		public MusicGroup GetAll(int groupId)
		{
			var group = db.Get(groupId);
			group.Tags = BizMusicGroupXTag.GetTagStringsByGroupID(groupId);

			return group;
		}
	}
}
